import store from "../store"
export default {
    install(globalVue){
        //全局添加在 扩展的vue的功能
        globalVue.component('quanjuzujian',{});
        globalVue.directive("my-permission",{
            //自定义指令 选项 生命周期钩子指的是它所在元素 或 组件的 创建 渲染 更新 销毁
            // <div my-permission:hello.enter="321" v-if="true"></div>
            // 参数 el 挂载的元素节点（html）对象  binding 调用指令的arg参数hello 和 modifiers修饰符.enter value值321
            //vnode vue创建的虚拟节点对象  prevnode 节点更新前的原虚拟节点
            created(el,binding,vnode,prevnode){
                console.log("el===>",el);
                console.log("binding===>",binding);
                console.log("vnode===>",vnode);
                console.log("prevnode===>",prevnode);
            },
            beforeMount(el,binding,vnode,prevnode){},
            mounted(el,binding,vnode,prevnode){
                let permissions=store.state.userStore.permissions&&store.state.userStore.permissions.role.permissions;
                let topmodule=binding.arg || "";//取出自定义指令的参数 :xxx
                let subaction=binding.value ||"";//取出自定义指令的值 my-permission:xxx="value"
                if(!permissions[topmodule] || !permissions[topmodule][subaction]){
                    el.remove();//删除节点.
                }
            },
            beforeUpdate(el,binding,vnode,prevnode){},
            updated(el,binding,vnode,prevnode){},
            beforeUnmount(el,binding,vnode,prevnode){},
            unmounted(el,binding,vnode,prevnode){}
        });    
    }
}